﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using DataBase.Daihoctuonglai;

namespace FarmeWork.Helper
{
    public class EmailHelper
    {
        public void GetStringMailSetting(int port, string MailFrom, string MailTo, string Sbject, string Body, string host, List<MailAddress> listMailBcc, EmailSystem entity)
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Port = port;
            smtp.Host = host;
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential(entity.Email, entity.Pass);
            MailMessage mail = new MailMessage(MailFrom, MailTo);
            mail.Subject = Sbject;
            mail.Body = Body;
            if (listMailBcc != null)
            {
                foreach (var item in listMailBcc)
                {
                    mail.Bcc.Add(item);
                }
            }
            mail.IsBodyHtml = true;
            try
            {
                smtp.Send(mail);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }

        public void EmailTemple(int port, string Content, EmailSystem entity, string mailto, string host, string TitleEmail, List<MailAddress> listMailBcc, string images, string hotline)
        {
            string Html = @"<!DOCTYPE HTML PUBLIC'-//IETF//DTD HTML//EN'>
                            <html>
                            <head>
                            <title></title>
                            </head>
                            <body>
                                <table align='center' border='0' cellpadding='0' cellspacing='0' style='background:#dddddd;font-family:Arial,Helvetica,sans-serif;font-size:12px' width='784'> "
                                + "<tbody><tr><td>"
                                       + " <table align='center' border='0' cellpadding='0' cellspacing='0' style='margin-top:28px' width='600'>"
                                         + "   <tbody> <tr>   <td style='width:600px;min-height:91px'> "
                                                 + " <div style='float:left;width:600px;min-height:91px;background:#041296'> "
                                                        + "<div style='float:left;width:152px;min-height:60px;margin:21px 0 0 38px;display:inline'> "
                                                            + " <img alt='sunnykao.com' src='images' style='font-size:18px;font-weight:bold;color:#fff' title='sunnykao.com travel'></div> "
                                                             + "<div style='float:left;margin:32px 0 0 30px;display:inline;font-size:20px;font-weight:normal;text-transform:uppercase;color:#fff'> "
                                                              + " " + TitleEmail + "</div></div></td> </tr> ";

            Html += "<tr><td style='background:#fff;width:100%'> ";
            Html += "<div style='padding:10px; line-height:22px;'>" + Content + "</div>";
            Html += "<span style='float:left;width:100%;min-height:58px;background:#f6f6f6;text-align:center;line-height:58px'>"
                    + "Nếu cần sự trợ giúp: <font style='color:#ff780c'>Hotline: <b> " + hotline + "</b> | "
                    + "Email: <b><a href='mailto:'" + entity.Email  + "' target='_blank'>" + entity.Email + "</a></b></font> </span> "
                    + "<p style='float:left;width:100%;padding-top:12px'>"
                        + "Trân trọng!<br> "
                        + "<img title='Nhóm phát triển '><br> "
                        + "<span style='color:#0054a6;text-decoration:none'><a href='http://sunnykao.com/' target='_blank'>www.sunnykao.com</a></span></p> "
                        + "</div><div style='float:left;width:552px;margin:30px 0 0 24px;display:inline;border-top:1px #666666 dotted;padding-top:15px;text-align:center;color:#888;line-height:normal'>"
                        + " <p style='width:100%;padding:0'> "
                        + " <a href='http://sunnykao.com/' style='color:#0054a6;text-decoration:none' title='' target='_blank'>Trang chủ</a> | "
                        + " <a href='http://sunnykao.com/Dich-Vu.aspx' style='color:#0054a6;text-decoration:none' title='' target='_blank'>Vé máy bay</a> | "
                        + " <a href='http://sunnykao.com/Tour-Trong-Nuoc.aspx' style='color:#0054a6;text-decoration:none' title='' target='_blank'>Tour Trrong Nước </a> | "
                        + "<a href='http://sunnykao.com/Tour-Ngoai-Nuoc.aspx' style='color:#0054a6;text-decoration:none' title='' target='_blank'>Tour Nước Ngoài</a></p> "
                        + "<p style='width:100%;padding:0'> "
                        + "[ Tin  trên mạng xã hội ]</p> "
                        + "<p style='width:100%;padding:0'> "
                        + "<a href='https://www.facebook.com/sunnykao' target='_blank'> "
                        + "Facebook</a> <a href='https://twitter.com/sunnykao' target='_blank'>Twitter</a></p>"
                        + "</div>";
            Html += "</td></tr>";
            Html += @"<tr><td><img height='18' width='600'></td> "
                        + "</tr><tr> <td> "
                            + "<div style='float:left;padding-left:12px;font-size:11px;color:#444;line-height:18px;padding-bottom:30px'>"
                            + "visa.com.vn <br> "
                            + "	Tel: (+84).313.272.498 | Fax (+84).313.272.498 | Email: <a href='#13a591392e615d98_' style='color:#0054a6;text-decoration:none' title=''>" + entity.Email + "</a><br>"
                            + " Địa chỉ : 03/53 Đồng Thiện - Vĩnh Niệm - Lê Chân - Hải Phòng.</div> "
                            + "	</td></tr></tbody></table></td></tr></tbody></table> "
                      + "</body> "
                    + "</html>";

            GetStringMailSetting(port, entity.Email, mailto, TitleEmail, Html, host, listMailBcc, entity);
        }

    }
}